package com.ruoyi.chatAi.config;

import com.ruoyi.chatAi.utils.UserChatMemory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatClientConfig {
    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Value("${spring.ai.openai.chat.options.defaultSystemPrompt}")
    private String defaultSystemPrompt;

    public ChatClient chatClient;


    @Bean
    public ChatClient myChatClient(ChatClient.Builder chatClientBuilder, UserChatMemory chatMemory) {
        this.chatClient = chatClientBuilder.defaultSystem(defaultSystemPrompt).defaultAdvisors(
                new SimpleLoggerAdvisor(),
                new MessageChatMemoryAdvisor(chatMemory)
        ).build();
        return chatClient;
    }

}
